package jdbc05;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;

import jdbc03.MyJdbcConnection;

public class jdbcBatch {

	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement stmt = null;

		try {
			conn = MyJdbcConnection.getConnection();
			stmt = conn.prepareStatement("insert into `besuper`.`player`(`id`,`name`,`score`,`username`,`password`) VALUES (?,?,?,?,?)");

			for (int i = 1; i < 21; i++) {
				stmt.setInt(1, i + 20);
				stmt.setString(2, "qingke" + i);
				stmt.setInt(3, 0);
				stmt.setString(4, "qingke" + i);
				stmt.setString(5, "root");
				
				stmt.addBatch();
			}
			
			int[] result = stmt.executeBatch();
			System.out.println("result: " + Arrays.toString(result));
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			MyJdbcConnection.clean(conn, stmt, null);
		}
	}

}
